/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.xuexiang.xui_lib.component.banner.transform;

import ohos.agp.components.Component;

/**
 * 3D旋转切换
 *
 * @since 2021-05-06
 */
public class DepthTransformer implements PageTransformer {
    private static final float SCALE_0_7_5 = 0.75F;
    private static final float SCALE_0_2_5 = 0.25F;
    private static final float SCALE_0_5 = 0.5F;

    @Override
    public void transformPage(Component component, float position) {
        if (position <= 0.0F) {
            component.setTranslationX(0.0F);
            component.setScaleX(1.0F);
            component.setScaleY(1.0F);
        } else if (position <= 1.0F) {
            float scaleFactor = SCALE_0_7_5 + SCALE_0_2_5 * ((float) 1 - Math.abs(position));
            component.setAlpha((float) 1 - position);
            component.setPivotY(SCALE_0_5 * (float) component.getHeight());
            component.setTranslationX((float) component.getWidth() * -position);
            component.setScaleX(scaleFactor);
            component.setScaleY(scaleFactor);
        }
    }
}
